package club.mzywucai.blog.air_portal.controller;

import club.mzywucai.blog.air_portal.pojo.domain.CreateNewFileCode;
import club.mzywucai.blog.air_portal.pojo.domain.JsonData;
import club.mzywucai.blog.air_portal.pojo.domain.MakeDir;
import club.mzywucai.blog.air_portal.pojo.po.FileInfoPo;
import club.mzywucai.blog.air_portal.pojo.po.UploadResult;
import club.mzywucai.blog.air_portal.service.AddFileInfoService;
import club.mzywucai.blog.air_portal.service.UploadService;
import club.mzywucai.blog.air_portal.util.SizeToStringUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author mzywucai
 * @Description
 * @date 2019/6/3
 */
@Data
@RestController
public class UploadController {
    @Autowired
    UploadService uploadService;

    /**
     * @Description 上传文件
     * @author mzywucai
     * @time 2019-06-04
     * @see 
     * @return   club.mzywucai.blog.air_portal.pojo.domain.JsonData
     * @params  [request, response]
     */
    @PostMapping("/api/user/upload")
    public JsonData upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
        JsonData json = uploadService.upload(request, response);

        return json;
    }
}
